/**
 * jims
 */
package com.jims.master.modules.csm.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.csm.dao.ExpStorageProfileDao;
import com.jims.master.modules.csm.entity.ExpStorageProfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 消耗品库存上下限Service
 * @author DT
 * @version 2017-03-28
 */
@Service
@Transactional(readOnly = true)
public class ExpStorageProfileService extends CrudService<ExpStorageProfileDao, ExpStorageProfile> {
	@Autowired
	private ExpStorageProfileDao expStorageProfileDao;
	public ExpStorageProfile get(String id) {
		return super.get(id);
	}
	
	public List<ExpStorageProfile> findList(ExpStorageProfile expStorageProfile) {
		return super.findList(expStorageProfile);
	}
	
	public Page<ExpStorageProfile> findPage(Page<ExpStorageProfile> page, ExpStorageProfile expStorageProfile) {
		return super.findPage(page, expStorageProfile);
	}

	public Page<ExpStorageProfile> findStorageWarning(Page<ExpStorageProfile> page, ExpStorageProfile expStorageProfile) {
		expStorageProfile.setPage(page);
		page.setList(expStorageProfileDao.findStorageWarning(expStorageProfile));
		return page;
	}

    /*
    * 获取一段时间内消耗品消耗量的list
    * ZhuQ
    * */
    public Page<ExpStorageProfile> findMinMaxList(Page<ExpStorageProfile> page, ExpStorageProfile expStorageProfile) {
        expStorageProfile.setPage(page);
        page.setList(expStorageProfileDao.findMinMaxList(expStorageProfile));
        return page;
    }

    /*
    * 根据infoId获取一条消耗量数据
    * ZhuQ
    * */
    public ExpStorageProfile findByInfoId(ExpStorageProfile expStorageProfile) {
        List<ExpStorageProfile> list=expStorageProfileDao.findMinMaxList(expStorageProfile);
        expStorageProfile=list.get(0);
		if(StringUtils.isNotBlank(expStorageProfile.getQuantity())){
			expStorageProfile.setQuantity(String.valueOf(Double.valueOf(expStorageProfile.getQuantity())/Double.valueOf(expStorageProfile.getPackageNum())));
		}
        if(!"".equals(expStorageProfile.getOutQuantity() )&& null !=expStorageProfile.getOutQuantity()){
            expStorageProfile.setOutQuantity(String.valueOf(Double.valueOf(expStorageProfile.getOutQuantity()) / Double.valueOf(expStorageProfile.getPackageNum())));
        }
        if(!"".equals(expStorageProfile.getMinQuantity() )&& null !=expStorageProfile.getMinQuantity()){
            expStorageProfile.setMinQuantity(String.valueOf(Double.valueOf(expStorageProfile.getMinQuantity()) / Double.valueOf(expStorageProfile.getPackageNum())));
        }
        if(!"".equals(expStorageProfile.getMaxQuantity() )&& null !=expStorageProfile.getMaxQuantity()){
            expStorageProfile.setMaxQuantity(String.valueOf(Double.valueOf(expStorageProfile.getMaxQuantity()) / Double.valueOf(expStorageProfile.getPackageNum())));
        }
        return expStorageProfile;
    }
	
	@Transactional(readOnly = false)
	public int save(ExpStorageProfile expStorageProfile) {
		return super.save(expStorageProfile);
	}
	
	@Transactional(readOnly = false)
	public int delete(ExpStorageProfile expStorageProfile) {
		return super.delete(expStorageProfile);
	}
	
}